<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
</head>

<body>

<input class="input">

<button class="send">send</button>

</body>

<script>
    $(function () {
        var ws = new WebSocket('ws://192.168.8.120:9902');
        // var ws = new WebSocket('ws://192.168.3.250:9902');

        ws.onopen = function()
        {

           console.log('websocket 连接上');
            // alert("数据发送中...");
        };

        ws.onmessage = function (evt)
        {
            var received_msg = JSON.parse(evt.data) ;
            console.log(received_msg);
            // alert("数据已接收...");
        };

        ws.onclose = function()
        {
            // 关闭 websocket
            console.log("连接已关闭...");
        };

        $('.send').click(function () {

            var input = $('.input').val().trim();

            if (input==null || input ==''){

                alert('输入不能为空');
            }



            var data = {};

            var value = {};

            value['uuid'] = '123456';
            value['command'] = input;

            data['path'] = 'index/screen';
            data['params'] = value;
            console.log(data);

            var mid= JSON.stringify(data);

            console.log(mid);



            // Web Socket 已连接上，使用 send() 方法发送数据
            ws.send(mid);

        })


        })




</script>
</html>
